package com.rongshu.view.userInfo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.rongshu.R;
import com.rongshu.view.userInfo.entity.PayDetail;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PayDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext = null;

    private List<PayDetail.ResponseBean> payDetails = null;

    public PayDetailAdapter(Context context) {
        this.mContext = context;
    }

    public void setPayDetails(List<PayDetail.ResponseBean> list) {
        this.payDetails = list;
    }

    public void addPayDetails(List<PayDetail.ResponseBean> list) {
        this.payDetails.addAll(list);
    }

    public List<PayDetail.ResponseBean> getPayDetails() {
        return this.payDetails;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_pay_detail_item_view, parent, false);
        return new PayDetailViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        PayDetail.ResponseBean payDetail = payDetails.get(position);
        PayDetailViewHolder holder = (PayDetailViewHolder) viewHolder;
        holder.txt_pay_recommend.setText(payDetail.getPay_way());
        holder.txt_pay_time.setText(payDetail.getAdd_time());
        holder.txt_pay_money.setTextColor(payDetail.getLogType().equals("消费") ?
                mContext.getResources().getColor(R.color.color_a5a5a5) :
                mContext.getResources().getColor(R.color.color_2c2c2c));
        holder.txt_pay_money.setText(payDetail.getLeaf());
    }

    @Override
    public int getItemCount() {
        return payDetails == null ? 0 : payDetails.size();
    }

    public class PayDetailViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_pay_recommend)
        TextView txt_pay_recommend;
        @BindView(R.id.txt_pay_time)
        TextView txt_pay_time;
        @BindView(R.id.txt_pay_money)
        TextView txt_pay_money;

        public PayDetailViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
